home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: What is wrong in this code?
- Date: Sat, 13 Jan 96 13:13:18 GMT
- Organization: none
- Message-ID: <821538798snz@genesis.demon.co.uk>
- References: <DL2z7o.2K5@scisun.sci.ccny.cuny.edu> <4d7kvv$j8@ub239.dialup.uwa.edu.au>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4d7kvv$j8@ub239.dialup.uwa.edu.au>
- prye@cyllene.uwa.edu.au "Peter Rye" writes:
-
- >>x = pow(x,x);
- > ^-------------------- This line is a problem.
- > I believe this will give rise to
- > "undefined behavior" because you
- > are modifying x using a function
- > which takes x as an argument.
-
- No, this is perfectly legal. The relevant par of the standard is in
- section 6.3:
-
- "Between the previous and next sequence point an object shall have its
- stored value modified at most once by the evaluation of an expression.
- Furthermore, the prior value shall be accessed only to determine the
- value to be stored"
-
- This expression meets the requirement of the 2nd sentence hence is legal.
- The fact that a function is involved is not important, except that
- a function call defines a sequence point. However that would increase,
- not reduce the likelihood of an expression being legal and doesn't affect
- an expression which is otherwise shown to be legal.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-